import { defineStore } from 'pinia';
import { formatRoutes } from '../utils/map-menus';
import localCache from '../utils/local-cache';
import type { RouteRequestItem } from '../utils/map-menus.type';

export const menuStore = defineStore('menu', {
    state: () => {
        return {
            menusList: [
                {
                    id: 1,
                    pid: null,
                    path: '/Layout/homePage',
                    name: 'homePage',
                    title: '首页',
                    icon: 'Home',
                    sort: 1,
                    type: 2, // 展开的层级
                    roles: [], // 权限数组
                    keep_alive: false,
                    children: null,
                },
                {
                    id: 2,
                    pid: null,
                    path: '/Layout/analysis',
                    name: 'analysis',
                    title: '数据报告',
                    icon: 'BarChart',
                    sort: 1,
                    type: 1, // 展开的层级
                    roles: [],
                    children: [
                        {
                            id: 5,
                            pid: 2,
                            path: '/Layout/analysis/dashboard',
                            name: 'dashboard',
                            title: '可视化面板',
                            icon: 'PieChart',
                            sort: 1,
                            type: 2, // 展开的层级
                            roles: [],
                            keep_alive: false,
                            children: null,
                        }
                    ]
                },
                {
                    id: 3,
                    pid: null,
                    path: '/Layout/system',
                    name: 'system',
                    title: '系统管理',
                    icon: 'Settings',
                    sort: 1,
                    type: 1, // 展开的层级
                    roles: [],
                    children: [
                        {
                            id: 6,
                            pid: 3,
                            path: '/Layout/system/users',
                            name: 'users',
                            title: '角色管理',
                            icon: 'People',
                            sort: 1,
                            type: 2, // 展开的层级
                            roles: [],
                            keep_alive: false,
                            children: null,
                        },
                        {
                            id: 7,
                            pid: 3,
                            path: '/Layout/system/menus',
                            title: '菜单管理',
                            name: 'menus',
                            icon: 'Menu',
                            sort: 1,
                            type: 2, // 展开的层级
                            roles: [],
                            keep_alive: false,
                            children: null,
                        }
                    ]
                },
                {
                    id: 4,
                    pid: null,
                    path: '/Layout/authorInformation',
                    name: 'authorInformation',
                    title: '作者介绍',
                    icon: 'Person',
                    sort: 1,
                    type: 2, // 展开的层级
                    roles: [], // 权限数组
                    keep_alive: false,
                    children: null,
                },
            ]
        }
    },
    actions: {
        // 映射菜单
        mapMenus() {
            const menusList: RouteRequestItem[] = this.menusList;
            const routes = formatRoutes(menusList);
            localCache.setCache('limitMenus', routes);
        }
    }
})